package com.example.framework;

import org.openqa.selenium.By;

public class NavigationHelper extends WebDriverHelper {

    public NavigationHelper(HelperManager manager) {
        super(manager);
    }

    public void gotoHomePage(){
        if (!onHomePage()) {
            click(By.linkText("home"));
        }
    }

    public void gotoGroupsPage() {
        if (!onGroupsPage()) {
            click(By.linkText("groups"));
        }
    }

    public void gotoAddNewContactPage() {
        if (!onAddNewContactPage()){
            click(By.linkText("add new"));
        }
    }

    //-------------------------------------------
    // Internal methods
    private boolean onHomePage() {
        return (driver.findElements(By.id("maintable")).size() > 0);
    }

    private boolean onGroupsPage() {
        if (driver.getCurrentUrl().contains("group.php")
                && driver.findElements(By.name("new")).size() > 0) {
            return true;
        }
        return false;
    }

    private boolean onAddNewContactPage() {
        if (driver.getCurrentUrl().contains("edit.php")
                && driver.findElements(By.name("submit")).size() > 0){
            return  true;
        }
        return false;
    }
}
